home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-01.zip / 01 / Hity z okladki / OrgPlus 6 SBE / ORGPL.CAB / indexPage.js < prev    next >
Text File  |  2006-09-20  |  10KB  |  410 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: indexPage.js                                 *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10.   window.onload = doInit
  11.   window.onresize = onResize
  12.  
  13.  
  14.   var bCapture = false
  15.  
  16.   function onResize()
  17.   { 
  18.     var nWidth = document.body.clientWidth
  19.  
  20.     if( typeof(PersonList) == "object" )
  21.       PersonList.style.width = nWidth + 3
  22.  
  23.     if( typeof(ListResizer) == "object" )
  24.       ListResizer.style.width = nWidth     
  25.   }
  26.  
  27.   function doInit()
  28.   {
  29.     CreateControls()
  30.     var obj = top.hcMain
  31.     if ( typeof (obj) == "object" && typeof (obj.onNavigatePageInit) != "undefined" )
  32.       obj.onNavigatePageInit()
  33.   }
  34.  
  35.   function clearPage()
  36.   {
  37.     CreateControls()
  38.     TitleText.innerText = ""
  39.     
  40.     var num = PersonList.length
  41.     for (i = num; i > 0; i--)
  42.       PersonList.remove(i-1)
  43.     //PersonList.innerText = ""
  44.  
  45.     PersonInfo.innerText = ""
  46.     top.hcMain.focus()
  47.   }
  48.   
  49.   var idxArray = null;
  50.   var idxCount = 0;
  51.  
  52.   function fillIndexArray(person)
  53.   {    
  54.     idxArray[idxCount++] = person    
  55.     var spanObjs = person.children.tags("span")
  56.  
  57.     for(var j = 0; j < spanObjs.length; ++j)
  58.     {
  59.       fillIndexArray(spanObjs[j])
  60.     }    
  61.     if(spanObjs.length == 0)
  62.       return
  63.   }    
  64.  
  65.   function fillPage(group)
  66.   {
  67.     clearPage()
  68.     if( typeof( group ) == "object" )
  69.     {
  70.       if(typeof( top.hcPersons ) == "object")
  71.       {
  72.         var fieldsObj = top.hcMain.getFieldsObj()
  73.         if(fieldsObj == null) return
  74.         var nID = ProcessHeaders(fieldsObj)
  75.         if (nID == -1)    
  76.           return; //Error! 
  77.             
  78.         var id = group.id
  79.         var objPerson = top.hcMain.findPersonNode(id,null)
  80.         if(objPerson == null)  return
  81.         idxArray = new Array()
  82.         idxCount = 0
  83.         fillIndexArray(objPerson)
  84.         for (j = 0; j < idxArray.length; j++)
  85.         {
  86.           AddListItem(idxArray[j], nID, j)
  87.         }    
  88.  
  89.         var objFirst = PersonList.options(0)
  90.         if ( objFirst != null && typeof(objFirst) == "object" )
  91.         {
  92.           objFirst.setAttribute('selected', true) 
  93.           ShowInfo(0)
  94.         }
  95.         top.hcMain.focus()
  96.         return                    
  97.       }      
  98.     }
  99.     top.hcMain.focus()
  100.   }
  101.  
  102.   function ProcessHeaders(objHeaders)
  103.   {
  104.     var nID = -1
  105.     if( typeof(objHeaders) == "object" )
  106.     {
  107.       var strTitle = ""
  108.           
  109.       var paramObjs = objHeaders.getElementsByTagName("param")
  110.       for (var j = 0; j < paramObjs.length; j++)
  111.       {
  112.         var obj = paramObjs(j)
  113.         if (obj.name != null)
  114.         {
  115.           if (strTitle == "")        
  116.             strTitle = obj.name
  117.  
  118.           if (nID == -1 && obj.id != null)
  119.             nID = obj.id
  120.           if (obj.value == "i")
  121.           {
  122.             strTitle = obj.name
  123.             if (obj.id != null)
  124.               nID = obj.id
  125.             break    
  126.           }
  127.         }
  128.       } //for
  129.  
  130.       TitleText.innerText = "Persons (" + strTitle + "):" //Loc
  131.     }
  132.  
  133.     return nID
  134.   }
  135.  
  136.   function CreateControls()
  137.   {
  138.     var topPos = 2
  139.     var elem
  140.  
  141.     if ( typeof(TitleText) == 'undefined' )
  142.     {
  143.       elem = document.createElement("v:textbox")
  144.       elem.className = 1
  145.       elem.id = "TitleText"
  146.       elem.style.top = topPos
  147.       elem.style.height = nFontSize
  148.       elem.style.width = 400
  149.       document.body.appendChild(elem)
  150.     }
  151.  
  152.     topPos += nFontSize + 1
  153.     var nListHeight = nFontSize * 20
  154.  
  155.     if ( typeof(PersonList) == 'undefined' )
  156.     {
  157.       elem = document.createElement("select")
  158.       elem.id = 'PersonList'
  159.       elem.className = 1
  160.       elem.style.top = topPos
  161.       elem.style.height = nListHeight
  162.       elem.style.left = -2
  163.       elem.size = 2
  164.       elem.multiple = false
  165.       document.body.appendChild(elem)
  166.     }
  167.  
  168.     topPos += nListHeight + 5 
  169.  
  170.     if ( typeof(ListResizer) == 'undefined' )
  171.     {
  172.       elem = document.createElement("hr")
  173.       elem.id = 'ListResizer'
  174.       elem.style.position = 'absolute'
  175.       elem.style.top = topPos
  176.       elem.style.height = 3
  177.       if (getIEVersion() < 6.0)
  178.         elem.style.cursor= 's-resize'
  179.       else
  180.         elem.style.cursor= 'row-resize'
  181.       elem.style.left = 0
  182.       elem.style.zIndex = 1
  183.       document.body.appendChild(elem)
  184.     }
  185.  
  186.     if ( typeof(PersonInfo) == 'undefined' )
  187.     {
  188.       elem = document.createElement("p")
  189.       elem.id = 'PersonInfo'
  190.       document.body.appendChild(elem)
  191.     }
  192.  
  193.     onResize()
  194.   }
  195.  
  196.   function AddListItem(objPerson, nID, nValue)           
  197.   {
  198.     var paramObjs = objPerson.getElementsByTagName("param")
  199.     var obj = null;
  200.     for (i = 0; i < paramObjs.length; ++i)
  201.     {      
  202.       var o = paramObjs(i)
  203.       if (o.id == nID)  
  204.       {
  205.         obj = o
  206.         break;
  207.       }
  208.     }
  209.     if (obj != null)
  210.     {      
  211.         var str = obj.name
  212.       if (typeof(str) != "undefined" && str != "")
  213.       {
  214.         var objOption = document.createElement("option")
  215.         objOption.text = str
  216.         objOption.value = nValue
  217.         PersonList.add(objOption)
  218.       }
  219.     }
  220.   }
  221.  
  222.   function ShowInfo(nPerson)
  223.   {
  224.     if ( idxArray != null && idxArray.length > nPerson)
  225.     {
  226.       PersonInfo.innerText = ""
  227.       var spanObj = idxArray[nPerson]
  228.       ShowPersonInfo(spanObj)            
  229.     }
  230.   }
  231.  
  232.   function ShowPersonInfo(objPerson)            
  233.   {
  234.     var fieldsObj = top.hcMain.getFieldsObj()
  235.     if ( fieldsObj == null)
  236.      return //Error
  237.  
  238.     var titleObjs = fieldsObj.children.tags("param")
  239.     var paramObjs = objPerson.children.tags("param")
  240.  
  241.     var k = 0;
  242.     for (i = 0; i < titleObjs.length; ++i)
  243.     {
  244.       var objTitle = titleObjs(i)
  245.       for (j = 0; j < paramObjs.length; j++)
  246.       {
  247.         var obj = paramObjs(j)
  248.         if (objTitle.id == obj.id)
  249.         {
  250.           var strName = objTitle.name
  251.           if ( typeof(strName) == 'undefined' )
  252.             strName = ""
  253.   
  254.           var strValue = obj.name
  255.           if ( typeof(strValue) == 'undefined' )
  256.             strValue = ""
  257.   
  258.           var strImage = obj.value
  259.           if ( typeof(strImage) == 'undefined' )
  260.             strImage = ""
  261.           
  262.           AddPersonInfoItem(k, strName, strValue, strImage)          
  263.           ++k;
  264.           break;
  265.         }
  266.       }
  267.     }
  268.   }
  269.  
  270.   function isEmail(str)
  271.   { 
  272.     return str.search('@') >= 0    
  273.   }
  274.  
  275.   var topPos = 0
  276.  
  277.   function AddPersonInfoItem(i, strName, strValue, strImage)
  278.   {
  279.     var bImageFlag = strImage.length > 0
  280.  
  281.     if (i == 0) 
  282.       topPos = parseInt(ListResizer.style.top) + 10 //nFontSize * 24
  283.     else
  284.       topPos += nFontSize + 1
  285.    
  286.     var elem = document.createElement("v:textbox");
  287.     var strText = strName + ':';
  288.     if (!bImageFlag) 
  289.       strText += '        ' + strValue; 
  290.     elem.style.width = strText.length * nFontSize
  291.     elem.innerText = strText
  292.     elem.className = 1
  293.     elem.style.top = topPos
  294.     elem.style.height = nFontSize
  295.  
  296.     if (!bImageFlag && isEmail(strValue))
  297.     {
  298.       var anc = document.createElement("a")
  299.       anc.setAttribute("href", "mailto:" + strValue)
  300.       PersonInfo.appendChild(anc)
  301.       anc.appendChild(elem)
  302.     }
  303.     else
  304.     {
  305.       PersonInfo.appendChild(elem)
  306.     }
  307.  
  308.     if (bImageFlag)
  309.     {
  310.       var nImageSize = nFontSize * 8
  311.       topPos += nFontSize + 1
  312.  
  313.       var objImage = document.createElement("img")
  314.       objImage.className = 1
  315.       objImage.style.top = topPos
  316.       PersonInfo.appendChild(objImage)
  317.       objImage.style.height = nImageSize
  318.       objImage.setAttribute("src", strImage) 
  319.  
  320.       topPos += nImageSize - nFontSize
  321.     }
  322.   }
  323.   
  324.   function OnSelected(strValue)
  325.   {
  326.     var nValue = parseInt(strValue)
  327.     ShowInfo(nValue)    
  328.   }
  329.  
  330.   function OnDblClicked(strValue)
  331.   {
  332.     var nPerson = parseInt(strValue)
  333.  
  334.     if ( idxArray != null && idxArray.length > nPerson)
  335.     {
  336.       var spanObj = idxArray[nPerson]
  337.       var strSrc  = spanObj.src 
  338.       if ( typeof(strSrc) == 'string' && strSrc != "")           
  339.             ShowBox(strSrc)      
  340.     }
  341.   }
  342.  
  343.  function ShowBox(strSrc)
  344.  { 
  345.     var hcMain = top.hcMain
  346.     //if (hcMain.location != strSrc)
  347.     {
  348.       var s = strSrc.split("#")
  349.       if(s.length!=2) return;
  350.  
  351.       if(s[0].length!=0)
  352.       {
  353.         if(hcMain.location.pathname.indexOf(s[0])!=-1)
  354.         {
  355.           hcMain.navigateBox(s[1]);
  356.         }
  357.         else 
  358.         {
  359.           hcMain.location.replace(strSrc)
  360.         }    
  361.       }
  362.       else
  363.       {
  364.         hcMain.navigateBox(s[1]);
  365.       }
  366.     }
  367.  } 
  368.  
  369.  
  370.  function OnResizerStartMoving()
  371.  {
  372.    ListResizer.setCapture()
  373.    bCapture = true
  374.  }
  375.     
  376.  function OnResizerMoving()
  377.  {
  378.    if (bCapture)
  379.      MoveResizer()
  380.  }
  381.  
  382.  function MoveResizer()
  383.  {
  384.    var y = window.event.clientY + document.body.scrollTop
  385.    var top = parseInt(PersonList.style.top) + 30
  386.    if (y <= top)
  387.      y = top
  388.    ListResizer.style.top = y
  389.  }
  390.     
  391.  function OnResizerMouseUp()
  392.  {
  393.    if (bCapture)
  394.    {
  395.      MoveResizer()
  396.  
  397.      var y = parseInt(ListResizer.style.top)
  398.      PersonList.style.height = y - 5 - parseInt(PersonList.style.top)
  399.  
  400.      var nItem = PersonList.selectedIndex
  401.      if (nItem >=0)
  402.        OnSelected( PersonList.options[ nItem ].value );
  403.    
  404.      ListResizer.releaseCapture()
  405.      bCapture = false
  406.  
  407.      onResize()
  408.    }
  409.  }
  410.